<template>
  <div class="count">
    <h3>作者是：{{author}}，大写：{{ upperAuthor }}</h3>
    <h3>当前求和为：{{sum}}，放大10被后：{{ bigSum }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <button @click="JIA(n)">+</button>
    <button @click="JIAN(n)">-</button>
    <button @click="jijia(n)">当前和为奇数再加</button>
    <button @click="dengjia(n)">等一等再加</button>
    <button @click="fuwujia">联系服务器再加</button>
  </div>
</template>

<script>
  import { mapGetters, mapState,mapActions, mapMutations } from 'vuex';
  export default {
    name: "Count",
    data() {
      return {
        n:1,
      }
    },
    computed: {
      ...mapState(['author','sum']),

      // mapGetters的第一种写法，对象式
      // ...mapGetters({'daxie':'upperAuthor','dahe':'bigSum'})

      // mapGetters的第二种写法，数组式
      ...mapGetters(['upperAuthor','bigSum']),
    },
    methods: {
      // 点击【+】的回调
      /* increment() {
        this.$store.commit("JIA", this.n);
      },
      // 点击【-】的回调
      decrement() {
        this.$store.commit("JIAN", this.n);
      }, */

      // mapMutations的对象写法
      // ...mapMutations({'increment':'JIA','decrement':'JIAN'}),

      // mapMutations的数组写法
      ...mapMutations(['JIA','JIAN']),


      ...mapActions(['jijia','dengjia','fuwujia'])
    },
  }
</script>

<style scoped>
.count {
  background-color: skyblue;
  padding: 10px;
}
button {
  margin-left: 10px;
}
</style>